
var ued_prefs = {
	prefs : null,
	opt_buf: {},
	init: 
	function () {
		this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
				.getService(Components.interfaces.nsIPrefService)
				.getBranch("uedigger.");
		this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
		this.prefs.addObserver("ued_prefs", this, false);

		this.opt_buf['hook_mouse'] = this.prefs.getBoolPref('hook_mouse');
		this.opt_buf['hook_key'] = this.prefs.getBoolPref('hook_key');
		this.opt_buf['hook_page'] = this.prefs.getBoolPref('hook_page');
		this.opt_buf['log_path'] = this.prefs.getCharPref('log_path');
		

	},

	clean:
	function () {
		this.prefs.removeObserver("ued_prefs", this);

	},

	// Called when events occur on the preferences
	observe: 
	function(subject, topic, data)
	{
		//if (topic != "nsPref:changed") {
		//	return;
		//}
		switch(data) {
			case "hook_mouse":
				this.opt_buf['hook_mouse'] = this.prefs.getBoolPref('hook_mouse');
			break;
			case "hook_key":
				this.opt_buf['hook_key'] = this.prefs.getBoolPref('hook_key');
			break;
			case "hook_page":
				this.opt_buf['hook_page'] = this.prefs.getBoolPref('hook_page');
			break;
			case "log_path":
				this.opt_buf['log_path'] = this.prefs.getCharPref('log_path');
			break;
			default:
			break;
		}
	},

	load:
	function () {
		this.opt_buf['hook_mouse'] = this.prefs.getBoolPref('hook_mouse');
		this.opt_buf['hook_key'] = this.prefs.getBoolPref('hook_key');
		this.opt_buf['hook_page'] = this.prefs.getBoolPref('hook_page');

		this.opt_buf['hook_back'] = this.prefs.getBoolPref('hook_back');
		this.opt_buf['hook_forward'] = this.prefs.getBoolPref('hook_forward');
		this.opt_buf['hook_reload'] = this.prefs.getBoolPref('hook_reload');
		this.opt_buf['hook_stop'] = this.prefs.getBoolPref('hook_stop');
		this.opt_buf['hook_home'] = this.prefs.getBoolPref('hook_home');

		this.opt_buf['log_path'] = this.prefs.getCharPref('log_path');
		return this.opt_buf;
	},
	
}

// Install load and unload handlers
window.addEventListener("load", function(e) { ued_prefs.init(); }, false);
window.addEventListener("unload", function(e) { ued_prefs.clean(); }, false);

